package com.cutie.user.service;

import java.sql.SQLException;

import com.cutie.core.util.RegexCheck;
import com.cutie.user.dao.UserDao;
import com.cutie.user.model.User;

public class UserService {

	UserDao userDao;
	
	public UserService(){
		userDao = new UserDao();
	}
	
	public String register(User user) throws SQLException{
		if(userDao.existName(user)){
			return "用户名已经存在";
		}else if(!RegexCheck.isEmail(user.getEmail())){
			return "邮箱格式错误";
		}else if(userDao.existEmail(user)){
			return "邮箱已经存在";
		}else{
			userDao.register(user);
			return "pass";
		}
	}
	
	public String login(User user) throws SQLException{
		if(!userDao.existName(user)){
			return "该用户名不存在";
		}else if(!userDao.login(user)){
			return "用户名和密码不匹配";
		}else{
			return "pass";
		}
		
	}
}
